
package net.lab0.electron.ai;


import java.util.LinkedList;


public class Population
extends LinkedList<Individual>
{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    public Population(int indivualCount)
    {
        super();
        for (int i = 0; i < indivualCount; ++i)
        {
            this.add(randomIndividual());
        }
        for (int i = 0; i < indivualCount; ++i)
        {
            System.out.println(this.get(i));
        }
    }
    
    private Individual randomIndividual()
    {
        // the root node of the individual that will be created
        return new Individual(randomGPNodeTree(10));
    }
    
    private GPNode randomGPNodeTree(int depth)
    {
        if (depth == 0)
        {
            switch (MyRandom.getRandInt() % 2)
            {
                case 0:
                    return new GPValueNode(MyRandom.getRandGauss());
                    
                default:
                    return new GPVarNode("x");
            }
        }
        else
        {
            int rand = MyRandom.getPositiveRandInt() % 4;
            switch (rand)
            {
                case 0:
                    return new GPAddNode(randomGPNodeTree(depth - 1), randomGPNodeTree(depth - 1));
                case 1:
                    return new GPMulNode(randomGPNodeTree(depth - 1), randomGPNodeTree(depth - 1));
                    
                case 2:
                    return new GPValueNode(MyRandom.getRandInt());
                case 3:
                    return new GPVarNode("x");
                    
                default:
                    return new GPVarNode("y_"+rand);
            }
        }
    }
    
    public static void main(String[] args)
    {
        new Population(10);
    }
}
